//看懂异步操作
document.getElementById("jump").onclick = () => {
    let result = confirm("确定跳转吗（请自行检查网址）");
    if (result == true) {
        document.querySelector(".photo").style.opacity = "0";
        document.getElementById("time").style.opacity = "1";
        document.querySelector(".button1").style.opacity = "0";
        document.querySelector(".button2").style.opacity = "1";
        document.querySelector(".button2").style.zIndex = "3";

        let url = document.getElementById("URL").value;
        let wait = document.getElementById("time");
        // setInterval和setTimeOut，都有返回值（如果还在运行则返回值不为null）
        // 他们都是异步的，可以通过后面的运行暂停
        let id = setInterval(() => {
            if (wait.innerHTML <= 0) {
                clearInterval(id);
                if (url == "") {
                    window.location = "https://www.wust.edu.cn";
                } else {
                    window.location = "https://" + url;
                }
            } else {
                wait.innerHTML = wait.innerHTML - 1;
            }
        }, 1000);//每隔1s执行一次

        //给stop添加点击事件
        document.getElementById("stop").addEventListener("click", () => {
            //如果id不为null就暂停
            //如果id为null则会显示暂停失败
            if (id) {
                clearInterval(id);
                alert("暂停成功");
            } else alert("暂停失败");
            document.querySelector(".photo").style.opacity = "1";
            document.getElementById("time").style.opacity = "0";
            document.querySelector(".button1").style.opacity = "1";
            document.querySelector(".button2").style.opacity = "0";
            document.querySelector(".button2").style.zIndex = "1";
        });
    }
}

